package com.ruoyi.zhgd.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.service.SysLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping()
public class VideoController extends BaseController {

    public String getVideoToken() {
        SysLoginService bean = SpringUtil.getBean(SysLoginService.class);
        return "Bearer " + bean.getVideoToken();
    }

    /**
     * 点击机构查询相机列表
     *
     * @param {*} data
     * @returns
     */
    @SaIgnore
    @PostMapping("/home/homeCamList")
    public Object homeCamList(@RequestBody JSONObject body) {
        String videoToken = getVideoToken();
        return HttpRequest.post("http://10.166.147.60:9021/home/homeCamList")
            .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36")
            .header(Header.AUTHORIZATION, videoToken)
            .body(body.toString())
            .execute().body();
    }

    /**
     * 获取视频流
     * @param {*} data
     */
    @SaIgnore
    @PostMapping("/home/videoStreaming")
    public Object videoStreaming(@RequestBody JSONObject body) {
        String videoToken = getVideoToken();
        return HttpRequest.post("http://10.166.147.60:9021/home/videoStreaming")
            .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36")
            .header(Header.AUTHORIZATION, videoToken)
            .body(body.toString())
            .execute().body();
    }

//    /**
//     * 关闭视频流
//     * @param {*} data
//     */
//    @SaIgnore
//    @GetMapping("/home/closeVideotape")
//    public Object closeVideotape() {
//        String videoToken = getVideoToken();
//        return HttpRequest.get("http://10.166.147.60:9021/home/closeVideotape")
//            .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36")
//            .header(Header.AUTHORIZATION, videoToken)
////            .form(params)
//            .execute().body();
//    }

    /**
     * 摄像机操作控制接口
     * @param {*} data
     */
    @SaIgnore
    @PostMapping("/home/PTZControl")
    public Object pTZControl(@RequestBody JSONObject body) {
        String videoToken = getVideoToken();
        return HttpRequest.post("http://10.166.147.60:9021/home/PTZControl")
            .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36")
            .header(Header.AUTHORIZATION, videoToken)
            .body(body.toString())
            .execute().body();
    }

    /**
     * 摄像机详情接口
     * @param {*} data
     */
    @SaIgnore
    @GetMapping("/system/camera/{id}")
    public Object camera(@PathVariable Long id) {
        String videoToken = getVideoToken();
        return HttpRequest.get("http://10.166.147.60:9021/system/camera/" + id)
            .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36")
            .header(Header.AUTHORIZATION, videoToken)
//            .form(params)
            .execute().body();
    }
}
